using System;
using System.Collections.Generic;
using System.ComponentModel;

using CureConsulting;
using CureConsulting.Business;

using Blog.Net.Common.DataObjects;

namespace Blog.Net.Business.BusinessObjects
{
	/// <summary>
	/// Business Object for blog_response.
	/// </summary>
	public partial class BlogResponseBO : BusinessObjectBase
	{
		#region Constructors

		/// <summary>
		/// Create a BlogResponseBO object
		/// </summary>
		public BlogResponseBO()
		{
			this.blogResponse = new BlogResponse();
		}

		/// <summary>
		/// Create a BlogResponseBO object
		/// </summary>
		public BlogResponseBO(int id) : this()
		{
			this.blogResponse.Id = id;
		}
		
		/// <summary>
		/// Create a BlogResponseBO object
		/// </summary>
		/// <param name="name"></param>
		/// <param name="email"></param>
		/// <param name="comment"></param>
		/// <param name="createDate"></param>
		/// <param name="blogEntry"></param>
		public BlogResponseBO( string name, string email, string comment, DateTime createDate, BlogEntryBO blogEntry ) : this()
		{
			this.blogResponse.Name = name;
			this.blogResponse.Email = email;
			this.blogResponse.Comment = comment;
			this.blogResponse.CreateDate = createDate;
			this.blogResponse.BlogEntry = blogEntry == null ? null : blogEntry.POCO;
		}

		/// <summary>
		/// Create a BlogResponseBO object
		/// </summary>
		/// <param name="BlogResponse"></param>
		public BlogResponseBO(BlogResponse blogResponse)
		{
			if(blogResponse != null)
			{
				this.blogResponse = blogResponse;
			}
			else
			{
				throw new ArgumentNullException();
			}
		}
		
		#endregion
		
		#region Member Variables
		
		private BlogResponse blogResponse;
		
		protected BlogEntryBO _blogEntry;
		
		#endregion
		
		#region Private Methods
		
		#endregion
		
		#region Public Properties
		
		/// <summary>
        /// Property for POCO
        /// </summary>
        public BlogResponse POCO
        {
            get { return blogResponse; }
        }
		
		/// <summary>
        /// Property for Id
        /// </summary>
        public override int? Id
        {
            get { return blogResponse.Id; }
			set
			{
				if(value.HasValue)
					blogResponse.Id = value;
			}
        }
		
		/// <summary>
		/// BlogResponse Name
		/// </summary>
		public virtual string Name
		{
			get { return blogResponse.Name; }
			set
			{				
				blogResponse.Name = (value != null && value.Length > 0) ? value : null;
				NotifyPropertyChanged("Name");
			}
		}

		/// <summary>
		/// BlogResponse Email
		/// </summary>
		public virtual string Email
		{
			get { return blogResponse.Email; }
			set
			{				
				blogResponse.Email = (value != null && value.Length > 0) ? value : null;
				NotifyPropertyChanged("Email");
			}
		}

		/// <summary>
		/// BlogResponse Comment
		/// </summary>
		public virtual string Comment
		{
			get { return blogResponse.Comment; }
			set
			{
				blogResponse.Comment = value;
				NotifyPropertyChanged("Comment");
			}
		}

		/// <summary>
		/// BlogResponse CreateDate
		/// </summary>
		public virtual DateTime CreateDate
		{
			get { return ConvertDateTimeFromDB(blogResponse.CreateDate); }
			set
			{
				blogResponse.CreateDate = ConvertDateTimeToDB(value);
				NotifyPropertyChanged("CreateDate");
			}
		}

		/// <summary>
		/// BlogResponse BlogEntry
		/// </summary>	
		public virtual BlogEntryBO BlogEntry
		{
			get
			{
				if(_blogEntry == null && blogResponse.BlogEntry != null)
					_blogEntry = new BlogEntryBO(blogResponse.BlogEntry);
					
				return _blogEntry;
			}
			set 
			{
				if (value != null)
				{
				 	_blogEntry = value;
				 	blogResponse.BlogEntry = _blogEntry.POCO;
				}
				else
				{
				 	_blogEntry = null;
				 	blogResponse.BlogEntry = null;
				}
				NotifyPropertyChanged("BlogEntry");
			}
		}
		
		/// <summary>
		/// BlogResponse BlogEntryId
		/// </summary>
		public virtual int? BlogEntryId
		{
			get
			{
				if (BlogEntry != null)
					return BlogEntry.Id;
					
				return null;
			}
			set 
			{
				if (value.HasValue)
					BlogEntry = new BlogEntryBO(value.Value);
			}
		}
		
		
		/// <summary>
        /// Property for Dirty
        /// </summary>
        public override bool Dirty
        {
            get { return blogResponse.Dirty; }
        }
		
		/// <summary>
        /// Property for IsNew
        /// </summary>
        public override bool IsNew
        {
            get { return blogResponse.IsNew; }
        }
		
		#endregion
		
		#region Public Methods
		
		/// <summary>
		/// Update a BlogResponseBO object
		/// </summary>
		public void UpdateBO(BlogResponse blogResponse)
		{
			this.blogResponse.Id = blogResponse.Id;
			this.blogResponse.Name = blogResponse.Name;
			this.blogResponse.Email = blogResponse.Email;
			this.blogResponse.Comment = blogResponse.Comment;
			this.blogResponse.CreateDate = blogResponse.CreateDate;
			this.blogResponse.BlogEntry = (blogResponse.BlogEntry == null) ? null : blogResponse.BlogEntry;
		}
		
		/// <summary>
		/// Override Equals to compare object properties.
		/// Note that child collections are ignored to avoid performance issues
		/// and possible circular references. Any DateTime properties will be considered equal
		/// if they differ by less than a second.  This is necessary because the RDBMS datetime data type
		/// (on Oracle or Sql Server) has less precision than the .Net DateTime struct.
		/// </summary>
		/// <param name="obj"></param>
		/// <returns></returns>
		public override bool Equals(object obj)
		{
			if(obj == null || obj.GetType() != this.GetType()) { return false; }
			
			if(Object.ReferenceEquals(this, obj)) { return true; }
			
			BlogResponseBO other = (BlogResponseBO)obj;

			return
			(
				this.Id == other.Id
				&& this.Name == other.Name
				&& this.Email == other.Email
				&& this.Comment == other.Comment
				&& this.CreateDate.Subtract(other.CreateDate).Duration().Ticks < TimeSpan.TicksPerSecond
				&& ( (this.BlogEntry == null && other.BlogEntry == null) || (this.BlogEntry != null && other.BlogEntry != null && this.BlogEntry.Id == other.BlogEntry.Id) ) 
			);
			
		}
		
		/// <summary>
		/// This class is mutable and therefore should not be used as a Hashtable key.
		/// GetHashCode will return the same value for all instances of this class.
		/// </summary>
		/// <returns></returns>
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		/// <summary>
		/// Reset the dirty flag
		/// </summary>
		public override void ResetDirty()
		{
			blogResponse.ResetDirty();
		}
		
		#endregion
	}
}